# Python2 中，请应用下面的语句，保证没有编码问题
from __future__ import unicode_literals

from django.http import HttpResponse
from django.shortcuts import render
from pyecharts.constants import DEFAULT_HOST


def line01(request):
    from pyecharts import Line

    line = Line("我的第一个折线图表", "这里是副标题")

    # 主要方法，用于添加图表的数据和设置各种配置项
    # 如果想要提供更多实用工具按钮，请在 add() 中设置 is_more_utils 为 True
    line.add(
        "一月份",
        ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],
        [5, 20, 36, 10, 75, 90],
        is_more_utils=True,
        mark_point=['max', 'min']
    )

    # 打印输出图表的所有配置项
    # bar.show_config()

    context = dict(
        title='line01',
        myechart=line.render_embed(),
        host=DEFAULT_HOST,
        script_list=line.get_js_dependencies()
    )

    return render(request, 'app01/line01.html', context)


def bar01(request):
    from pyecharts import Bar

    bar = Bar("我的第一个柱状图表", "这里是副标题")

    # 主要方法，用于添加图表的数据和设置各种配置项
    # 如果想要提供更多实用工具按钮，请在 add() 中设置 is_more_utils 为 True
    bar.add(
        "一月份",
        ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],
        [5, 20, 36, 10, 75, 90],
        is_more_utils=True,
        mark_point=['max', 'min']
    )

    bar.add(
        "二月份",
        ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],
        [15, 30, 46, 50, 85, 40],
        is_stack=True,
        is_more_utils=False
    )

    context = dict(
        title='bar01',
        myechart=bar.render_embed(),
        host=DEFAULT_HOST,
        script_list=bar.get_js_dependencies()
    )

    return render(request, 'app01/bar01.html', context)


def pie01(request):
    from pyecharts import Pie

    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    v1 = [5, 20, 36, 10, 75, 90]
    v2 = [15, 30, 46, 50, 85, 40]

    pie = Pie("我的第一个饼状图表", "这里是副标题", width=900)

    # 主要方法，用于添加图表的数据和设置各种配置项
    # 如果想要提供更多实用工具按钮，请在 add() 中设置 is_more_utils 为 True
    pie.add("商品1", attr, v1)
    pie.add("商品2", attr, v2)

    context = dict(
        title='pie01',
        myechart=pie.render_embed(),
        host=DEFAULT_HOST,
        script_list=pie.get_js_dependencies()
    )

    return render(request, 'app01/pie01.html', context)


def overlap01(request):
    from pyecharts import Line, Bar, Overlap

    line = Line("我的第一个折线图表", "这里是副标题")
    line.add(
        "一月份",
        ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],
        [65, 80, 76, 90, 75, 95],
    )

    bar = Bar("我的第一个柱状图表", "这里是副标题")
    bar.add(
        "一月份",
        ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],
        [5, 20, 36, 10, 45, 60],
        is_more_utils=True,
        mark_point=['max', 'min']
    )
    bar.add(
        "二月份",
        ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],
        [15, 30, 46, 50, 45, 40],
        is_more_utils=False
    )

    o = Overlap()
    o.add(line)
    o.add(bar)

    context = dict(
        title='pie01',
        myechart=o.render_embed(),
        host=DEFAULT_HOST,
        script_list=o.get_js_dependencies()
    )

    return render(request, 'app01/pie01.html', context)
